package com.example.app06_component;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 初始化视图对象并设置点击事件
        findViewById(R.id.btn_main_simple).setOnClickListener(this);
        findViewById(R.id.btn_main_menu).setOnClickListener(this);
        findViewById(R.id.btn_main_progressbar).setOnClickListener(this);
        findViewById(R.id.btn_main_dialog).setOnClickListener(this);
    }

    /**
     * 处理点击事件
     * @param v 发生事件的视图对象
     */
    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.btn_main_simple) {
            startActivity(new Intent(this, SimpleComponentActivity.class));
        } else if(v.getId() == R.id.btn_main_menu) {
            startActivity(new Intent(this, MenuActivity.class));
        } else if(v.getId() == R.id.btn_main_progressbar) {
            startActivity(new Intent(this, ProgressbarActivity.class));
        } else if (v.getId() == R.id.btn_main_dialog) {
            startActivity(new Intent(this, DialogActivity.class));
        }
    }
}